package com.md.youyouhui.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.md.youyouhui.R;
import com.md.youyouhui.net.response.GetSellResponse;

import java.util.List;

/**
 * Created by AdministratorZJ
 * on 2019/5/21.
 */
public class ShoppingTitleAdapter extends RecyclerView.Adapter<ShoppingTitleAdapter.MyViewHolder> {
    private Context context;
    private ShoppingInfoAdapter infoAdapter;
    private List<GetSellResponse> data;

    public ShoppingTitleAdapter(Context context) {
        this.context = context;
    }

    public void upDate(List<GetSellResponse> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.adapter_shopping_title, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
        myViewHolder.title.setText(data.get(i).columnTitle);
        if (myViewHolder.infoRecycler.getAdapter() == null) {
            infoAdapter = new ShoppingInfoAdapter(context);
            myViewHolder.infoRecycler.setAdapter(infoAdapter);
        }
        infoAdapter = (ShoppingInfoAdapter) myViewHolder.infoRecycler.getAdapter();
        infoAdapter.upDate(data.get(i).sellColumnLinks);
    }

    @Override
    public int getItemCount() {
        return null == data ? 0 : data.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        public RecyclerView infoRecycler;
        public TextView title;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            title = itemView.findViewById(R.id.shoppingTitle);
            infoRecycler = itemView.findViewById(R.id.titleRecycler);
            LinearLayoutManager layoutManager = new LinearLayoutManager(itemView.getContext());
            layoutManager.setAutoMeasureEnabled(true);
            infoRecycler.setLayoutManager(layoutManager);
        }
    }
}


